package com.qfedu.yanglao20admin.camera.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qfedu.yanglao20.common.CommonResult;
import com.qfedu.yanglao20.common.utils.OssUtils;
import com.qfedu.yanglao20.entity.advertising.AdvertisingContent;
import com.qfedu.yanglao20admin.camera.param.CameraListParam;
import com.qfedu.yanglao20admin.camera.service.CameraListService;
import com.qfedu.yanglao20admin.camera.vo.CameraListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * 摄像头列表信息控制层
 */
@Api(tags = "摄像头列表信息")
@RestController
@RequestMapping("/CameraList")
public class CameraListController {

    @Resource
    private CameraListService cameraListService;

    @ApiOperation(value = "查询所有摄像头列表信息", notes = "查询所有摄像头列表信息")
    @GetMapping("/all")
    public CommonResult queryAllCameraList() {
        List<CameraListVO> cameraListVOS = cameraListService.selectListAll();
        return CommonResult.success(cameraListVOS);
    }

    @ApiOperation(value = "根据id删除摄像头列表信息", notes = "根据id删除摄像头列表信息")
    @GetMapping("/delete")
    public CommonResult deleteCameraLIst(@RequestParam @ApiParam("摄像头列表id") Integer id) {
        cameraListService.deleteById(id);
        return CommonResult.success();
    }

    @ApiOperation(value = "分页展示摄像头列表信息", notes = "分页展示摄像头列表信息")
    @GetMapping("/list")
    public CommonResult<CameraListParam> advertisingContentList(CameraListParam param) {
        Page<CameraListVO> cameraListVOPage = cameraListService.pageCameraList(param);
        return CommonResult.success(cameraListVOPage);
    }

    @ApiOperation(value = "添加摄像头列表信息", notes = "添加摄像头列表信息")
    @PostMapping("/add")
    public CommonResult<CameraListVO> addCameraList(CameraListVO cameraListVO) {
        cameraListService.add(cameraListVO);
        return CommonResult.success();
    }
    @ApiOperation(value = "根据id查询摄像头列表信息", notes = "根据id查询摄像头列表信息")
    @GetMapping("/query")
    public CommonResult queryCameraList(@RequestParam @ApiParam("摄像头列表信息id") Integer id) {
        CameraListVO cameraListVO = cameraListService.selectById(id);
        return CommonResult.success(cameraListVO);
    }
    @ApiOperation(value = "修改摄像头列表信息", notes = "修改摄像头列表信息")
    @PostMapping("/update")
    public CommonResult<CameraListVO> updateCameraList(CameraListVO cameraListVO) {
        cameraListService.update(cameraListVO);
        return CommonResult.success();
    }
    @ApiOperation(value = "上传监控视频", notes = "上传监控视频")
    @PostMapping("/upload")
    public CommonResult<AdvertisingContent> upload(MultipartFile file) {

        String path = null;
        try {
            path = OssUtils.uploadFile2OSS(file.getInputStream(), file.getOriginalFilename());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return CommonResult.success(path);
    }
}
